package student.aistar.mapper;

import org.apache.ibatis.annotations.*;
import student.aistar.model.entity.Collect;
import student.aistar.model.entity.Orders;
import student.aistar.model.entity.Product;
import student.aistar.model.entity.User;

import java.util.List;

public interface PersonalCenterMapper {

    //根据用户id查询我的喜欢
    @Select("select * from collect where user_id = #{userId}")
    List<Collect> selectMyLike(Integer userId);


    //根据产品id和用户id删除我的喜欢
    @Delete("delete from collect where product_id = #{productId} and user_id = #{userId}")
    void deleteMyLike(Integer productId, Integer userId);

    //根据id查询用户信息
    @Select("select * from user where user_id=#{userId}")
    User selectById(Integer userId);

    //根据用户id更新昵称和性别和头像
    @Update("update user set user_name=#{userName},sex=#{sex},user_img=#{userImg} where  user_id=#{userId}")
    void updateById(@Param("userId") Integer userId, @Param("userName") String userName, @Param("sex") String sex,@Param("userImg") String userImg);

    //根据用户姓名查找信息
    @Select("select * from user where user_name=#{userName}")
    User selectUserByName(String userName);

    //根据用户id更新手机号
    @Update("update user set user_telephone=#{userTelephone} where  user_id=#{userId}")
    int updateTelephone(Integer userId,String userTelephone);

    //根据用户id更新邮箱
    @Update("update user set user_email=#{userEmail} where  user_id=#{userId}")
    int updateEmail(Integer userId,String userEmail);

    //根据用户id更新密码
    @Update("update user set user_password=#{userPassword} where  user_id=#{userId}")
    int updatePassword(Integer userId,String userPassword);

    //点一下增加我的喜欢
    @Insert("insert into collect values(#{collectId},#{userId},#{productId},#{productName},#{productPig},#{price},#{paraName})")
    void insertProductToLike(Collect collect);

    //再点一下删除我的喜欢
    @Delete("delete from collect where collect_id = #{collectId}")
    void deleteProductToLike(Integer collectId);

    //根据用户id查询订单信息
    @Select("select count(order_status) from orders where user_id = #{userId} and order_status = 1")
    int selectOrdersStatusByUserId(Integer userId);

    @Select("select count(order_status) from orders where user_id = #{userId} and order_status = 2")
    int selectOrdersStatusByUserId2(Integer userId);

    //根据用户id查喜欢商品个数
    @Select("select count(collect_id) from collect where user_id = #{userId}")
    int selectCountLike(Integer userId);

    @Select("select * from collect where user_id=#{userId} and product_id = #{productId}")
    Collect selectCollectionByUserIdAndProductId(Integer userId,Integer productId);
}
